﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bussiness;

namespace WebApplication.Admin
{
    public partial class BaoCaoXuattheoThang : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (! IsPostBack)
            {
                LoadMathang();
            }
        }

        protected void lbtnxem_Click(object sender, EventArgs e)
        {
            if (Dlthang.SelectedValue.Equals("0") || Dlnam.SelectedValue.Equals("0"))
            {
                RegisterClientScriptBlock("Thông báo", "<script> alert('Vui lòng chọn tháng và năm')</script>");
                return;
            }
            Microsoft.Reporting.WebForms.ReportDataSource source;
            int thang=int.Parse(Dlthang.SelectedValue);
            int nam=int.Parse(Dlnam.SelectedValue);
            string ngay=DateTime.Now.ToString("dd/MM/yyyy");
            if (Dlmathang.SelectedValue.Equals("0"))
            {
                source = new Microsoft.Reporting.WebForms.ReportDataSource("BaoCaoXuatTheoThang", new Baocao.BaoCaoXuatTheoThang().GetBaoCaoXuatTheoThang(thang, nam, ngay));
                ReportViewer1.LocalReport.ReportPath = @"Admin\Baocao\BaoCaoXuatTheoThang.rdlc";
                ReportViewer1.LocalReport.DataSources.Clear();
                ReportViewer1.LocalReport.DataSources.Add(source);
                ReportViewer1.LocalReport.Refresh();
            }
            else
            {
                string mamh=Dlmathang.SelectedValue;
                source = new Microsoft.Reporting.WebForms.ReportDataSource("BaoCaoXuatTheoThang", new Baocao.BaoCaoXuatTheoThang().GetBaoCaoXuatTheoThang(thang, nam, ngay,mamh));
                ReportViewer1.LocalReport.ReportPath = @"Admin\Baocao\BaoCaoXuatTheoThang.rdlc";
                ReportViewer1.LocalReport.DataSources.Clear();
                ReportViewer1.LocalReport.DataSources.Add(source);
                ReportViewer1.LocalReport.Refresh();
            }
        }
        public void LoadMathang()
        {
            IUnitOfWork iunitfwork = new EFUnitOfWork();
            MATHANGRepository repository = new MATHANGRepository(new EFRepository<MATHANG>(), iunitfwork);
            IQueryable<MATHANG> objmathang = repository.All();
            Dlmathang.DataSource = objmathang;
            Dlmathang.DataValueField = "MAMH";
            Dlmathang.DataTextField = "TENMH";
            Dlmathang.DataBind();
            Dlmathang.Items.Insert(0, new ListItem { Text = "---Chọn mặt hàng---", Value = "0" });
            Dlnam.Items.Insert(0, new ListItem {Text="---Chọn năm---",Value="0" });
            Dlthang.Items.Insert(0, new ListItem { Text = "---Chọn tháng---", Value = "0" });
        }
    }
}